1 LOADING LIBRARIES

library(readr)
library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(ggplot2)
library(corrplot)
## corrplot 0.95 loaded
library(C50)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

2 Introduction

Predicting the sales of four different product types and assessing the impact of service reviews and customer reviews on sales Goals 1. Predicting Sales: To predict the sales of four different product types — PCs, Laptops, Netbooks, and Smartphones — using historical sales data and relevant influencing factors. 2. Assessing Review Impact: To assess the impact that service reviews and customer reviews have on the sales performance of these product types, identifying key factors that drive or hinder sales.

3 Data Descrtption

The Existing product has 80 observations and 18 variables. We have one of the variable which is catergorical “Product Type” and we have the rest to be numerical. The data was given which the project statement as an attachment ## Data Summary & Structure** 1. The dataset contained 80 observations and 18 variables, primarily numeric, with one categorical variable (ProductType).

3.1 loading the dataset

sales <- read.csv("existingproductattributes2017.csv")
summary(sales)
##  ProductType          ProductNum        Price         x5StarReviews   
##  Length:80          Min.   :101.0   Min.   :   3.60   Min.   :   0.0  
##  Class :character   1st Qu.:120.8   1st Qu.:  52.66   1st Qu.:  10.0  
##  Mode  :character   Median :140.5   Median : 132.72   Median :  50.0  
##                     Mean   :142.6   Mean   : 247.25   Mean   : 176.2  
##                     3rd Qu.:160.2   3rd Qu.: 352.49   3rd Qu.: 306.5  
##                     Max.   :200.0   Max.   :2249.99   Max.   :2801.0  
##                                                                       
##  x4StarReviews    x3StarReviews    x2StarReviews    x1StarReviews    
##  Min.   :  0.00   Min.   :  0.00   Min.   :  0.00   Min.   :   0.00  
##  1st Qu.:  2.75   1st Qu.:  2.00   1st Qu.:  1.00   1st Qu.:   2.00  
##  Median : 22.00   Median :  7.00   Median :  3.00   Median :   8.50  
##  Mean   : 40.20   Mean   : 14.79   Mean   : 13.79   Mean   :  37.67  
##  3rd Qu.: 33.00   3rd Qu.: 11.25   3rd Qu.:  7.00   3rd Qu.:  15.25  
##  Max.   :431.00   Max.   :162.00   Max.   :370.00   Max.   :1654.00  
##                                                                      
##  PositiveServiceReview NegativeServiceReview Recommendproduct BestSellersRank
##  Min.   :  0.00        Min.   :  0.000       Min.   :0.100    Min.   :    1  
##  1st Qu.:  2.00        1st Qu.:  1.000       1st Qu.:0.700    1st Qu.:    7  
##  Median :  5.50        Median :  3.000       Median :0.800    Median :   27  
##  Mean   : 51.75        Mean   :  6.225       Mean   :0.745    Mean   : 1126  
##  3rd Qu.: 42.00        3rd Qu.:  6.250       3rd Qu.:0.900    3rd Qu.:  281  
##  Max.   :536.00        Max.   :112.000       Max.   :1.000    Max.   :17502  
##                                                               NA's   :15     
##  ShippingWeight     ProductDepth      ProductWidth    ProductHeight   
##  Min.   : 0.0100   Min.   :  0.000   Min.   : 0.000   Min.   : 0.000  
##  1st Qu.: 0.5125   1st Qu.:  4.775   1st Qu.: 1.750   1st Qu.: 0.400  
##  Median : 2.1000   Median :  7.950   Median : 6.800   Median : 3.950  
##  Mean   : 9.6681   Mean   : 14.425   Mean   : 7.819   Mean   : 6.259  
##  3rd Qu.:11.2050   3rd Qu.: 15.025   3rd Qu.:11.275   3rd Qu.:10.300  
##  Max.   :63.0000   Max.   :300.000   Max.   :31.750   Max.   :25.800  
##                                                                       
##   ProfitMargin        Volume     
##  Min.   :0.0500   Min.   :    0  
##  1st Qu.:0.0500   1st Qu.:   40  
##  Median :0.1200   Median :  200  
##  Mean   :0.1545   Mean   :  705  
##  3rd Qu.:0.2000   3rd Qu.: 1226  
##  Max.   :0.4000   Max.   :11204  
## 
attributes(sales)
## $names
##  [1] "ProductType"           "ProductNum"            "Price"                
##  [4] "x5StarReviews"         "x4StarReviews"         "x3StarReviews"        
##  [7] "x2StarReviews"         "x1StarReviews"         "PositiveServiceReview"
## [10] "NegativeServiceReview" "Recommendproduct"      "BestSellersRank"      
## [13] "ShippingWeight"        "ProductDepth"          "ProductWidth"         
## [16] "ProductHeight"         "ProfitMargin"          "Volume"               
## 
## $class
## [1] "data.frame"
## 
## $row.names
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## [51] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
## [76] 76 77 78 79 80
structure(sales)
##         ProductType ProductNum   Price x5StarReviews x4StarReviews
## 1                PC        101  949.00             3             3
## 2                PC        102 2249.99             2             1
## 3                PC        103  399.00             3             0
## 4            Laptop        104  409.99            49            19
## 5            Laptop        105 1079.99            58            31
## 6       Accessories        106  114.22            83            30
## 7       Accessories        107  379.99            11             3
## 8       Accessories        108   65.29            33            19
## 9       Accessories        109  119.99            16             9
## 10      Accessories        110   16.99            10             1
## 11      Accessories        111    6.55            21             2
## 12      Accessories        112   15.00            75            25
## 13      Accessories        113   52.50            10             8
## 14      Accessories        114   21.08           313            62
## 15      Accessories        115   18.98           349           118
## 16      Accessories        116    3.60             8             6
## 17      Accessories        117    3.60            11             5
## 18      Accessories        118  174.99           170           100
## 19      Accessories        119    9.99            15            12
## 20         Software        120  670.00            20             2
## 21         Software        121  133.08            34            15
## 22         Software        122  124.99           394           187
## 23         Software        123   56.99           513           217
## 24         Software        124   48.50            29            18
## 25         Software        125   31.99            77            31
## 26          Display        126  179.99           306           114
## 27          Printer        127  396.35             8             0
## 28          Printer        128  262.98            22             8
## 29  PrinterSupplies        129   83.11             0             0
## 30  PrinterSupplies        130   26.78             6             2
## 31  PrinterSupplies        131   43.22             5             0
## 32 ExtendedWarranty        132   79.98             0             1
## 33 ExtendedWarranty        133   87.98             5             0
## 34 ExtendedWarranty        134  124.98           308            27
## 35 ExtendedWarranty        135  129.98           308            27
## 36 ExtendedWarranty        136  134.98           308            27
## 37 ExtendedWarranty        137  151.98           308            27
## 38 ExtendedWarranty        138  169.98           308            27
## 39 ExtendedWarranty        139  179.98           308            27
## 40 ExtendedWarranty        140  189.50           308            27
## 41 ExtendedWarranty        141  349.99           308            27
## 42               PC        142  609.99            21             7
## 43           Laptop        143  770.60            22            14
## 44      Accessories        144    3.84            92            29
## 45      Accessories        145    6.99           384            31
## 46      Accessories        146   59.99           366            59
## 47      Accessories        147   38.66           209            83
## 48      Accessories        148   10.75           535           261
## 49      Accessories        149  126.95            13             2
## 50      Accessories        150   49.99          2801           431
## 51      Accessories        151  103.85             3             0
## 52      Accessories        152   52.72            51            33
## 53      Accessories        153   19.99           474            38
## 54      Accessories        154   16.24           108            54
## 55      Accessories        155   69.00           226            37
## 56          Display        156  359.99            90            27
## 57          Display        157 1276.57           164            33
## 58          Display        158  783.98            26            13
## 59          Display        159  149.99            21            10
## 60          Printer        160  129.99            74            25
## 61          Printer        161  128.49            58            33
## 62          Printer        162  141.95             4             0
## 63          Printer        163  149.99             8             3
## 64          Printer        164  165.99             2             0
## 65          Printer        165  169.26            20            13
## 66          Printer        166  132.36             0             1
## 67          Printer        167  149.99           206            89
## 68          Printer        168  395.00             8             0
## 69          Printer        169  385.96            99            43
## 70          Netbook        177  379.99             1             0
## 71           Tablet        185  499.00           148            66
## 72       Smartphone        190  199.00             4             1
## 73      GameConsole        198  129.00          1759           296
## 74           Tablet        188  499.00            86            51
## 75           Tablet        189  419.00             3             1
## 76       Smartphone        191  200.00            62            25
## 77       Smartphone        192   99.00            18            17
## 78          Netbook        182  349.99            22            10
## 79       Smartphone        197  499.00           368            28
## 80      GameConsole        200  299.99           421            87
##    x3StarReviews x2StarReviews x1StarReviews PositiveServiceReview
## 1              2             0             0                     2
## 2              0             0             0                     1
## 3              0             0             0                     1
## 4              8             3             9                     7
## 5             11             7            36                     7
## 6             10             9            40                    12
## 7              0             0             1                     3
## 8             12             5             9                     5
## 9              2             0             2                     2
## 10             1             0             0                     2
## 11             2             4            15                     2
## 12             6             3             3                     9
## 13             5             0             1                     2
## 14            13             8            16                    44
## 15            27             7             5                    57
## 16             3             2             1                     0
## 17             2             2             1                     0
## 18            23            20            20                   310
## 19             4             0             4                     3
## 20             4             2             4                     4
## 21             2             2            10                     5
## 22            63            42            86                    55
## 23           162           370          1654                   144
## 24             3             1             8                     4
## 25             7             3             2                     7
## 26            25            22            28                    42
## 27             1             0             2                     1
## 28             3             1             3                     5
## 29             0             1             3                     1
## 30             0             0             1                     1
## 31             0             0             0                     1
## 32             1             1             1                     0
## 33             2             0             1                     0
## 34             8             3            15                   280
## 35             8             3            15                   280
## 36             8             3            15                   280
## 37             8             3            15                   280
## 38             8             3            15                   280
## 39             8             3            15                   280
## 40             8             3            15                   280
## 41             8             3            15                   280
## 42             3             0            12                     5
## 43             4             5             6                     6
## 44             8             4            10                    12
## 45            13             5            20                    50
## 46            23            26            24                    60
## 47            35            38            36                    15
## 48           134           104           177                   120
## 49             2             2             5                     5
## 50           157           154           270                   536
## 51             0             0             0                     1
## 52             8             7             4                     6
## 53             7             6            12                    80
## 54            12             2             6                     7
## 55             3             7             8                    13
## 56            10             4             4                     7
## 57             6            13             6                    12
## 58             7             5            16                     4
## 59             3             1             4                     4
## 60             7             6             9                     4
## 61            10             3             6                     5
## 62             0             0             3                     0
## 63             3             2             0                     0
## 64             1             1             2                     1
## 65             8             6            21                     4
## 66             0             0             0                     0
## 67            20            22            65                    42
## 68             1             0             2                     3
## 69            17            11            20                     8
## 70             1             1             0                     0
## 71            30            20            29                    12
## 72             0             2             2                     1
## 73           109            56            44                    56
## 74            17            12             9                    14
## 75             0             0             0                     0
## 76            10            11            12                     9
## 77             6             2            12                     5
## 78             6             2            10                     3
## 79            14            10            23                    22
## 80            20            14            39                    29
##    NegativeServiceReview Recommendproduct BestSellersRank ShippingWeight
## 1                      0              0.9            1967          25.80
## 2                      0              0.9            4806          50.00
## 3                      0              0.9           12076          17.40
## 4                      8              0.8             109           5.70
## 5                     20              0.7             268           7.00
## 6                      5              0.3              64           1.60
## 7                      0              0.9              NA           7.30
## 8                      3              0.7               2          12.00
## 9                      1              0.8              NA           1.80
## 10                     0              0.9              18           0.75
## 11                     1              0.5              NA           1.00
## 12                     2              0.2               7           2.20
## 13                     0              0.8              NA           1.10
## 14                     3              0.9               6           0.35
## 15                     3              0.9              NA           0.60
## 16                     0              0.8             927           0.01
## 17                     0              0.8             661           0.01
## 18                     6              0.8               1           1.40
## 19                     1              0.8              NA           0.40
## 20                     3              0.7             110           0.25
## 21                     4              0.7              NA           3.20
## 22                    38              0.8               1           0.15
## 23                   112              0.3             398           0.55
## 24                     2              0.8             150           0.20
## 25                     0              0.9             281           0.20
## 26                    12              0.8               2          13.70
## 27                     1              0.3              60          63.00
## 28                     1              0.8              29          57.00
## 29                     1              0.1           17502          10.30
## 30                     0              0.9              NA           1.00
## 31                     0              1.0              NA           1.00
## 32                     3              0.4               5           0.20
## 33                     1              0.6              11           0.20
## 34                     8              0.9              16           0.20
## 35                     8              0.9               7           0.20
## 36                     8              0.9               7           0.20
## 37                     8              0.9               7           0.20
## 38                     8              0.9               7           0.20
## 39                     8              0.9               7           0.20
## 40                     8              0.9               7           0.20
## 41                     8              0.9               7           0.20
## 42                     3              0.6              NA          29.10
## 43                     2              0.7            1473           3.54
## 44                     3              0.8              17           1.00
## 45                     1              0.9               9           1.00
## 46                     5              0.8              22           2.40
## 47                     4              0.7              11           0.40
## 48                    15              0.7               3           1.50
## 49                     1              0.6              17           3.00
## 50                    22              0.8              30           0.40
## 51                     0              0.9             100           8.00
## 52                     1              0.8               3           4.00
## 53                     2              0.9              22           1.50
## 54                     3              0.9              27           0.55
## 55                     1              0.9              27           3.80
## 56                     3              0.9               1           7.00
## 57                     4              0.9               8          23.00
## 58                     5              0.6              50          25.00
## 59                     2              0.8              48          10.00
## 60                     2              0.9               6          32.20
## 61                     2              0.9              11          22.70
## 62                     1              0.5              76          25.00
## 63                     0              0.7              NA          35.00
## 64                     1              0.5              NA          31.00
## 65                     7              0.5              NA          32.00
## 66                     0              0.8              NA          30.20
## 67                    50              0.7              10          13.00
## 68                     0              0.8              69          63.00
## 69                    13              0.7              NA          39.00
## 70                     1              0.3            6295           3.00
## 71                     6              0.8             134           2.20
## 72                     1              0.5             829           1.10
## 73                    13              0.9             215           7.25
## 74                     2              0.8               4           2.00
## 75                     0              0.9             544           2.20
## 76                     3              0.8             720           0.90
## 77                     4              0.7            5742           0.70
## 78                     3              0.3            2723           5.00
## 79                     3              0.9           14086           0.90
## 80                    14              0.9             352          10.94
##    ProductDepth ProductWidth ProductHeight ProfitMargin Volume
## 1         23.94         6.62         16.89         0.15     12
## 2         35.00        31.75         19.00         0.25      8
## 3         10.50         8.30         10.20         0.08     12
## 4         15.00         9.90          1.30         0.08    196
## 5         12.90         0.30          8.90         0.09    232
## 6          5.80         4.00          1.00         0.05    332
## 7          6.70        10.30         11.50         0.05     44
## 8          7.90         6.70          2.20         0.05    132
## 9         10.60         9.40          4.70         0.05     64
## 10        10.70        13.10          0.60         0.05     40
## 11         7.30         7.00          1.60         0.05     84
## 12        21.30         1.80          7.80         0.05    300
## 13        15.60         3.00         15.00         0.05     40
## 14         5.70         3.50          8.30         0.05   1252
## 15         1.70        13.50         10.20         0.05   1396
## 16        11.50         8.50          0.40         0.05     32
## 17        11.50         8.50          0.40         0.05     44
## 18        13.80         8.20          0.40         0.05    680
## 19        11.10         7.60          0.50         0.05     60
## 20         5.80         1.40          7.80         0.15     80
## 21         7.40         5.50          1.40         0.15    136
## 22         7.60         5.50          1.20         0.20   1576
## 23         5.20         1.40          7.50         0.15   2052
## 24         8.00         7.00          1.00         0.20    116
## 25         0.00         0.00          0.00         0.30    308
## 26         8.50        22.30         17.50         0.08   1224
## 27        17.90        15.90         12.70         0.12     32
## 28        17.30        23.50         25.80         0.12     88
## 29         0.00         0.00          0.00         0.35      0
## 30         3.30         1.60          4.70         0.30     24
## 31         4.70         2.90          6.30         0.30     20
## 32         0.00         0.00          0.00         0.40      0
## 33         0.00         0.00          0.00         0.40     20
## 34         0.00         0.00          0.00         0.40   1232
## 35         0.00         0.00          0.00         0.40   1232
## 36         0.00         0.00          0.00         0.40   1232
## 37         0.00         0.00          0.00         0.40   1232
## 38         0.00         0.00          0.00         0.40   1232
## 39         0.00         0.00          0.00         0.40   1232
## 40         0.00         0.00          0.00         0.40   1232
## 41         0.00         0.00          0.00         0.40   1232
## 42        20.95         8.47         20.71         0.09     84
## 43        12.72         8.90          0.71         0.15     88
## 44         6.50         4.20          1.50         0.05    368
## 45       108.00         0.50          0.50         0.05   1536
## 46         7.90         1.40         19.10         0.05   1464
## 47         3.60         6.50          8.80         0.05    836
## 48        11.50        20.00          7.20         0.05   2140
## 49         5.90         1.80          6.70         0.05     52
## 50         7.00         4.50          1.20         0.05  11204
## 51         4.80         1.30          4.80         0.05     12
## 52         6.60         5.50          5.20         0.05    204
## 53       300.00         0.50          0.50         0.05   1896
## 54         6.00         3.00          8.20         0.05    432
## 55        15.00         9.80         18.90         0.05    904
## 56         9.20        11.20          3.20         0.20    360
## 57        15.50        17.70          5.70         0.25    656
## 58        29.20         9.90         23.00         0.16    104
## 59        20.00        15.30          6.40         0.17     84
## 60        15.70        15.90         12.40         0.10    296
## 61        15.70        15.90         10.60         0.12    232
## 62        19.50        18.00         14.00         0.14     16
## 63        10.20        15.98         14.55         0.18     32
## 64        22.10        18.60         13.50         0.18      8
## 65        15.10        11.70         19.60         0.16     80
## 66        20.90        20.90         14.60         0.20      0
## 67         8.80        13.70          7.60         0.15    824
## 68        17.90        15.90         12.70         0.09     32
## 69        21.00        15.40         17.90         0.11    396
## 70         7.44        10.43          1.02         0.10      4
## 71         7.10        10.40          0.30         0.13    592
## 72         4.50         2.50          0.50         0.10     16
## 73         8.50         6.00          1.75         0.18   7036
## 74        10.10         6.90          0.38         0.20    344
## 75         7.00        10.20          0.40         0.18     12
## 76         2.80         5.40          0.30         0.14    248
## 77         2.80         5.30          0.40         0.17     72
## 78         7.57        10.47          1.43         0.12     88
## 79         2.70         5.00          0.40         0.10   1472
## 80        12.00        11.50          7.25         0.12   1684
names(sales)
##  [1] "ProductType"           "ProductNum"            "Price"                
##  [4] "x5StarReviews"         "x4StarReviews"         "x3StarReviews"        
##  [7] "x2StarReviews"         "x1StarReviews"         "PositiveServiceReview"
## [10] "NegativeServiceReview" "Recommendproduct"      "BestSellersRank"      
## [13] "ShippingWeight"        "ProductDepth"          "ProductWidth"         
## [16] "ProductHeight"         "ProfitMargin"          "Volume"

4 Data Preprocessing

4.1 checking for duplicate

duplicated(sales)
##  [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

4.2 checking for missing values

is.na(sales)
##       ProductType ProductNum Price x5StarReviews x4StarReviews x3StarReviews
##  [1,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
##  [2,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
##  [3,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
##  [4,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
##  [5,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
##  [6,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
##  [7,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
##  [8,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
##  [9,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [10,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [11,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [12,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [13,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [14,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [15,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [16,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [17,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [18,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [19,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [20,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [21,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [22,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [23,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [24,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [25,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [26,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [27,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [28,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [29,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [30,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [31,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [32,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [33,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [34,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [35,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [36,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [37,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [38,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [39,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [40,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [41,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [42,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [43,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [44,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [45,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [46,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [47,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [48,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [49,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [50,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [51,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [52,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [53,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [54,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [55,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [56,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [57,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [58,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [59,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [60,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [61,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [62,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [63,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [64,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [65,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [66,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [67,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [68,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [69,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [70,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [71,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [72,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [73,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [74,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [75,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [76,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [77,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [78,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [79,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
## [80,]       FALSE      FALSE FALSE         FALSE         FALSE         FALSE
##       x2StarReviews x1StarReviews PositiveServiceReview NegativeServiceReview
##  [1,]         FALSE         FALSE                 FALSE                 FALSE
##  [2,]         FALSE         FALSE                 FALSE                 FALSE
##  [3,]         FALSE         FALSE                 FALSE                 FALSE
##  [4,]         FALSE         FALSE                 FALSE                 FALSE
##  [5,]         FALSE         FALSE                 FALSE                 FALSE
##  [6,]         FALSE         FALSE                 FALSE                 FALSE
##  [7,]         FALSE         FALSE                 FALSE                 FALSE
##  [8,]         FALSE         FALSE                 FALSE                 FALSE
##  [9,]         FALSE         FALSE                 FALSE                 FALSE
## [10,]         FALSE         FALSE                 FALSE                 FALSE
## [11,]         FALSE         FALSE                 FALSE                 FALSE
## [12,]         FALSE         FALSE                 FALSE                 FALSE
## [13,]         FALSE         FALSE                 FALSE                 FALSE
## [14,]         FALSE         FALSE                 FALSE                 FALSE
## [15,]         FALSE         FALSE                 FALSE                 FALSE
## [16,]         FALSE         FALSE                 FALSE                 FALSE
## [17,]         FALSE         FALSE                 FALSE                 FALSE
## [18,]         FALSE         FALSE                 FALSE                 FALSE
## [19,]         FALSE         FALSE                 FALSE                 FALSE
## [20,]         FALSE         FALSE                 FALSE                 FALSE
## [21,]         FALSE         FALSE                 FALSE                 FALSE
## [22,]         FALSE         FALSE                 FALSE                 FALSE
## [23,]         FALSE         FALSE                 FALSE                 FALSE
## [24,]         FALSE         FALSE                 FALSE                 FALSE
## [25,]         FALSE         FALSE                 FALSE                 FALSE
## [26,]         FALSE         FALSE                 FALSE                 FALSE
## [27,]         FALSE         FALSE                 FALSE                 FALSE
## [28,]         FALSE         FALSE                 FALSE                 FALSE
## [29,]         FALSE         FALSE                 FALSE                 FALSE
## [30,]         FALSE         FALSE                 FALSE                 FALSE
## [31,]         FALSE         FALSE                 FALSE                 FALSE
## [32,]         FALSE         FALSE                 FALSE                 FALSE
## [33,]         FALSE         FALSE                 FALSE                 FALSE
## [34,]         FALSE         FALSE                 FALSE                 FALSE
## [35,]         FALSE         FALSE                 FALSE                 FALSE
## [36,]         FALSE         FALSE                 FALSE                 FALSE
## [37,]         FALSE         FALSE                 FALSE                 FALSE
## [38,]         FALSE         FALSE                 FALSE                 FALSE
## [39,]         FALSE         FALSE                 FALSE                 FALSE
## [40,]         FALSE         FALSE                 FALSE                 FALSE
## [41,]         FALSE         FALSE                 FALSE                 FALSE
## [42,]         FALSE         FALSE                 FALSE                 FALSE
## [43,]         FALSE         FALSE                 FALSE                 FALSE
## [44,]         FALSE         FALSE                 FALSE                 FALSE
## [45,]         FALSE         FALSE                 FALSE                 FALSE
## [46,]         FALSE         FALSE                 FALSE                 FALSE
## [47,]         FALSE         FALSE                 FALSE                 FALSE
## [48,]         FALSE         FALSE                 FALSE                 FALSE
## [49,]         FALSE         FALSE                 FALSE                 FALSE
## [50,]         FALSE         FALSE                 FALSE                 FALSE
## [51,]         FALSE         FALSE                 FALSE                 FALSE
## [52,]         FALSE         FALSE                 FALSE                 FALSE
## [53,]         FALSE         FALSE                 FALSE                 FALSE
## [54,]         FALSE         FALSE                 FALSE                 FALSE
## [55,]         FALSE         FALSE                 FALSE                 FALSE
## [56,]         FALSE         FALSE                 FALSE                 FALSE
## [57,]         FALSE         FALSE                 FALSE                 FALSE
## [58,]         FALSE         FALSE                 FALSE                 FALSE
## [59,]         FALSE         FALSE                 FALSE                 FALSE
## [60,]         FALSE         FALSE                 FALSE                 FALSE
## [61,]         FALSE         FALSE                 FALSE                 FALSE
## [62,]         FALSE         FALSE                 FALSE                 FALSE
## [63,]         FALSE         FALSE                 FALSE                 FALSE
## [64,]         FALSE         FALSE                 FALSE                 FALSE
## [65,]         FALSE         FALSE                 FALSE                 FALSE
## [66,]         FALSE         FALSE                 FALSE                 FALSE
## [67,]         FALSE         FALSE                 FALSE                 FALSE
## [68,]         FALSE         FALSE                 FALSE                 FALSE
## [69,]         FALSE         FALSE                 FALSE                 FALSE
## [70,]         FALSE         FALSE                 FALSE                 FALSE
## [71,]         FALSE         FALSE                 FALSE                 FALSE
## [72,]         FALSE         FALSE                 FALSE                 FALSE
## [73,]         FALSE         FALSE                 FALSE                 FALSE
## [74,]         FALSE         FALSE                 FALSE                 FALSE
## [75,]         FALSE         FALSE                 FALSE                 FALSE
## [76,]         FALSE         FALSE                 FALSE                 FALSE
## [77,]         FALSE         FALSE                 FALSE                 FALSE
## [78,]         FALSE         FALSE                 FALSE                 FALSE
## [79,]         FALSE         FALSE                 FALSE                 FALSE
## [80,]         FALSE         FALSE                 FALSE                 FALSE
##       Recommendproduct BestSellersRank ShippingWeight ProductDepth ProductWidth
##  [1,]            FALSE           FALSE          FALSE        FALSE        FALSE
##  [2,]            FALSE           FALSE          FALSE        FALSE        FALSE
##  [3,]            FALSE           FALSE          FALSE        FALSE        FALSE
##  [4,]            FALSE           FALSE          FALSE        FALSE        FALSE
##  [5,]            FALSE           FALSE          FALSE        FALSE        FALSE
##  [6,]            FALSE           FALSE          FALSE        FALSE        FALSE
##  [7,]            FALSE            TRUE          FALSE        FALSE        FALSE
##  [8,]            FALSE           FALSE          FALSE        FALSE        FALSE
##  [9,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [10,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [11,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [12,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [13,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [14,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [15,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [16,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [17,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [18,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [19,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [20,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [21,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [22,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [23,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [24,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [25,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [26,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [27,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [28,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [29,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [30,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [31,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [32,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [33,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [34,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [35,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [36,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [37,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [38,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [39,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [40,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [41,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [42,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [43,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [44,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [45,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [46,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [47,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [48,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [49,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [50,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [51,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [52,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [53,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [54,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [55,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [56,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [57,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [58,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [59,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [60,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [61,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [62,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [63,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [64,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [65,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [66,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [67,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [68,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [69,]            FALSE            TRUE          FALSE        FALSE        FALSE
## [70,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [71,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [72,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [73,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [74,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [75,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [76,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [77,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [78,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [79,]            FALSE           FALSE          FALSE        FALSE        FALSE
## [80,]            FALSE           FALSE          FALSE        FALSE        FALSE
##       ProductHeight ProfitMargin Volume
##  [1,]         FALSE        FALSE  FALSE
##  [2,]         FALSE        FALSE  FALSE
##  [3,]         FALSE        FALSE  FALSE
##  [4,]         FALSE        FALSE  FALSE
##  [5,]         FALSE        FALSE  FALSE
##  [6,]         FALSE        FALSE  FALSE
##  [7,]         FALSE        FALSE  FALSE
##  [8,]         FALSE        FALSE  FALSE
##  [9,]         FALSE        FALSE  FALSE
## [10,]         FALSE        FALSE  FALSE
## [11,]         FALSE        FALSE  FALSE
## [12,]         FALSE        FALSE  FALSE
## [13,]         FALSE        FALSE  FALSE
## [14,]         FALSE        FALSE  FALSE
## [15,]         FALSE        FALSE  FALSE
## [16,]         FALSE        FALSE  FALSE
## [17,]         FALSE        FALSE  FALSE
## [18,]         FALSE        FALSE  FALSE
## [19,]         FALSE        FALSE  FALSE
## [20,]         FALSE        FALSE  FALSE
## [21,]         FALSE        FALSE  FALSE
## [22,]         FALSE        FALSE  FALSE
## [23,]         FALSE        FALSE  FALSE
## [24,]         FALSE        FALSE  FALSE
## [25,]         FALSE        FALSE  FALSE
## [26,]         FALSE        FALSE  FALSE
## [27,]         FALSE        FALSE  FALSE
## [28,]         FALSE        FALSE  FALSE
## [29,]         FALSE        FALSE  FALSE
## [30,]         FALSE        FALSE  FALSE
## [31,]         FALSE        FALSE  FALSE
## [32,]         FALSE        FALSE  FALSE
## [33,]         FALSE        FALSE  FALSE
## [34,]         FALSE        FALSE  FALSE
## [35,]         FALSE        FALSE  FALSE
## [36,]         FALSE        FALSE  FALSE
## [37,]         FALSE        FALSE  FALSE
## [38,]         FALSE        FALSE  FALSE
## [39,]         FALSE        FALSE  FALSE
## [40,]         FALSE        FALSE  FALSE
## [41,]         FALSE        FALSE  FALSE
## [42,]         FALSE        FALSE  FALSE
## [43,]         FALSE        FALSE  FALSE
## [44,]         FALSE        FALSE  FALSE
## [45,]         FALSE        FALSE  FALSE
## [46,]         FALSE        FALSE  FALSE
## [47,]         FALSE        FALSE  FALSE
## [48,]         FALSE        FALSE  FALSE
## [49,]         FALSE        FALSE  FALSE
## [50,]         FALSE        FALSE  FALSE
## [51,]         FALSE        FALSE  FALSE
## [52,]         FALSE        FALSE  FALSE
## [53,]         FALSE        FALSE  FALSE
## [54,]         FALSE        FALSE  FALSE
## [55,]         FALSE        FALSE  FALSE
## [56,]         FALSE        FALSE  FALSE
## [57,]         FALSE        FALSE  FALSE
## [58,]         FALSE        FALSE  FALSE
## [59,]         FALSE        FALSE  FALSE
## [60,]         FALSE        FALSE  FALSE
## [61,]         FALSE        FALSE  FALSE
## [62,]         FALSE        FALSE  FALSE
## [63,]         FALSE        FALSE  FALSE
## [64,]         FALSE        FALSE  FALSE
## [65,]         FALSE        FALSE  FALSE
## [66,]         FALSE        FALSE  FALSE
## [67,]         FALSE        FALSE  FALSE
## [68,]         FALSE        FALSE  FALSE
## [69,]         FALSE        FALSE  FALSE
## [70,]         FALSE        FALSE  FALSE
## [71,]         FALSE        FALSE  FALSE
## [72,]         FALSE        FALSE  FALSE
## [73,]         FALSE        FALSE  FALSE
## [74,]         FALSE        FALSE  FALSE
## [75,]         FALSE        FALSE  FALSE
## [76,]         FALSE        FALSE  FALSE
## [77,]         FALSE        FALSE  FALSE
## [78,]         FALSE        FALSE  FALSE
## [79,]         FALSE        FALSE  FALSE
## [80,]         FALSE        FALSE  FALSE
sum(is.na(sales))
## [1] 15
sales$BestSellersRank <- NULL

5 Data structure

  1. There were no missing values or duplicates after cleaning.
  2. The variable BestSellersRank was removed due to irrelevance or missing data.
boxplot(sales$ProductNum)

boxplot(sales$Price)

boxplot(sales$x5StarReviews)

boxplot(sales$x4StarReviews)

boxplot(sales$x3StarReviews)

boxplot(sales$x2StarReviews)

boxplot(sales$x1StarReviews)

boxplot(sales$PositiveServiceReview)

boxplot(sales$PositiveServiceReview)

boxplot(sales$NegativeServiceReview)

boxplot(sales$Recommendproduct)

boxplot(sales$ShippingWeight)

boxplot(sales$ProductDepth)

boxplot(sales$ProductWidth)

boxplot(sales$ProductHeight)

boxplot(sales$ProfitMargin)

boxplot(sales$Volume)

6 Dummify the data

newDataFrame <- dummyVars(" ~ . ", data = sales)
readyData <- data.frame(predict(newDataFrame, newdata = sales))

7 Correlation between the relevant independent variables

corrData <-  cor(readyData)
corrData
##                             ProductTypeAccessories ProductTypeDisplay
## ProductTypeAccessories                 1.000000000        -0.17916128
## ProductTypeDisplay                    -0.179161283         1.00000000
## ProductTypeExtendedWarranty           -0.262265264        -0.09759001
## ProductTypeGameConsole                -0.111111111        -0.04134491
## ProductTypeLaptop                     -0.136963567        -0.05096472
## ProductTypeNetbook                    -0.111111111        -0.04134491
## ProductTypePC                         -0.159188978        -0.05923489
## ProductTypePrinter                    -0.291491544        -0.10846523
## ProductTypePrinterSupplies            -0.136963567        -0.05096472
## ProductTypeSmartphone                 -0.159188978        -0.05923489
## ProductTypeSoftware                   -0.197582993        -0.07352146
## ProductTypeTablet                     -0.136963567        -0.05096472
## ProductNum                            -0.338862490         0.08407390
## Price                                 -0.384906124         0.23172981
## x5StarReviews                          0.127803771        -0.03758386
## x4StarReviews                          0.156715126        -0.00293832
## x3StarReviews                          0.110608918        -0.03849540
## x2StarReviews                          0.033055555        -0.02708636
## x1StarReviews                         -0.041647041        -0.03628464
## PositiveServiceReview                  0.002699224        -0.09438421
## NegativeServiceReview                 -0.148034357        -0.01861755
## Recommendproduct                       0.058505351         0.07239820
## ShippingWeight                        -0.341367875         0.10374059
## ProductDepth                           0.191398963         0.01528395
## ProductWidth                          -0.154462467         0.28447123
## ProductHeight                         -0.060521774         0.18486593
## ProfitMargin                          -0.626935212         0.03906690
## Volume                                 0.127803771        -0.03758386
##                             ProductTypeExtendedWarranty ProductTypeGameConsole
## ProductTypeAccessories                      -0.26226526           -0.111111111
## ProductTypeDisplay                          -0.09759001           -0.041344912
## ProductTypeExtendedWarranty                  1.00000000           -0.060522753
## ProductTypeGameConsole                      -0.06052275            1.000000000
## ProductTypeLaptop                           -0.07460471           -0.031606977
## ProductTypeNetbook                          -0.06052275           -0.025641026
## ProductTypePC                               -0.08671100           -0.036735918
## ProductTypePrinter                          -0.15877684           -0.067267279
## ProductTypePrinterSupplies                  -0.07460471           -0.031606977
## ProductTypeSmartphone                       -0.08671100           -0.036735918
## ProductTypeSoftware                         -0.10762440           -0.045596075
## ProductTypeTablet                           -0.07460471           -0.031606977
## ProductNum                                  -0.08607897            0.340268975
## Price                                       -0.09780278           -0.015543759
## x5StarReviews                                0.07086528            0.388298241
## x4StarReviews                               -0.09946665            0.344636607
## x3StarReviews                               -0.09934446            0.258709076
## x2StarReviews                               -0.09348376            0.074429824
## x1StarReviews                               -0.05189306            0.003300983
## PositiveServiceReview                        0.62710951           -0.014267327
## NegativeServiceReview                        0.01528844            0.081949267
## Recommendproduct                             0.14451833            0.126534828
## ShippingWeight                              -0.23680262           -0.006072795
## ProductDepth                                -0.15707124           -0.019260720
## ProductWidth                                -0.43640441            0.022014271
## ProductHeight                               -0.34555286           -0.041136327
## ProfitMargin                                 0.80226723           -0.006230125
## Volume                                       0.07086528            0.388298241
##                             ProductTypeLaptop ProductTypeNetbook ProductTypePC
## ProductTypeAccessories           -0.136963567        -0.11111111   -0.15918898
## ProductTypeDisplay               -0.050964719        -0.04134491   -0.05923489
## ProductTypeExtendedWarranty      -0.074604710        -0.06052275   -0.08671100
## ProductTypeGameConsole           -0.031606977        -0.02564103   -0.03673592
## ProductTypeLaptop                 1.000000000        -0.03160698   -0.04528334
## ProductTypeNetbook               -0.031606977         1.00000000   -0.03673592
## ProductTypePC                    -0.045283341        -0.03673592    1.00000000
## ProductTypePrinter               -0.082918499        -0.06726728   -0.09637388
## ProductTypePrinterSupplies       -0.038961039        -0.03160698   -0.04528334
## ProductTypeSmartphone            -0.045283341        -0.03673592   -0.05263158
## ProductTypeSoftware              -0.056205010        -0.04559608   -0.06532553
## ProductTypeTablet                -0.038961039        -0.03160698   -0.04528334
## ProductNum                       -0.187367237         0.22272699   -0.26383058
## Price                             0.296140664         0.05587061    0.54711260
## x5StarReviews                    -0.069799582        -0.07001054   -0.10289168
## x4StarReviews                    -0.052974299        -0.08017983   -0.12221649
## x3StarReviews                    -0.045679827        -0.05874134   -0.10093459
## x2StarReviews                    -0.038007390        -0.04311403   -0.06931004
## x1StarReviews                    -0.021994035        -0.02819859   -0.04287299
## PositiveServiceReview            -0.085716506        -0.07750629   -0.10938596
## NegativeServiceReview             0.052417536        -0.04759253   -0.08835918
## Recommendproduct                 -0.011740126        -0.36327741    0.09356725
## ShippingWeight                   -0.055573162        -0.06005908    0.31738315
## ProductDepth                     -0.005033888        -0.03192360    0.05401162
## ProductWidth                     -0.042331972         0.06221219    0.20211260
## ProductHeight                    -0.075600667        -0.11774247    0.34991734
## ProfitMargin                     -0.081632386        -0.06160902   -0.02380242
## Volume                           -0.069799582        -0.07001054   -0.10289168
##                             ProductTypePrinter ProductTypePrinterSupplies
## ProductTypeAccessories            -0.291491544                -0.13696357
## ProductTypeDisplay                -0.108465229                -0.05096472
## ProductTypeExtendedWarranty       -0.158776837                -0.07460471
## ProductTypeGameConsole            -0.067267279                -0.03160698
## ProductTypeLaptop                 -0.082918499                -0.03896104
## ProductTypeNetbook                -0.067267279                -0.03160698
## ProductTypePC                     -0.096373885                -0.04528334
## ProductTypePrinter                 1.000000000                -0.08291850
## ProductTypePrinterSupplies        -0.082918499                 1.00000000
## ProductTypeSmartphone             -0.096373885                -0.04528334
## ProductTypeSoftware               -0.119617833                -0.05620501
## ProductTypeTablet                 -0.082918499                -0.03896104
## ProductNum                         0.249589095                -0.09325018
## Price                             -0.037212288                -0.11477363
## x5StarReviews                     -0.149200679                -0.09040334
## x4StarReviews                     -0.133159178                -0.11100268
## x3StarReviews                     -0.121109706                -0.09486115
## x2StarReviews                     -0.087025567                -0.05819149
## x1StarReviews                     -0.060204072                -0.03866021
## PositiveServiceReview             -0.184785826                -0.09649048
## NegativeServiceReview              0.008126681                -0.08180838
## Recommendproduct                  -0.149914932                -0.07882656
## ShippingWeight                     0.757676417                -0.07272702
## ProductDepth                       0.029243566                -0.06686404
## ProductWidth                       0.555981505                -0.18418343
## ProductHeight                      0.515703796                -0.07473566
## ProfitMargin                      -0.055691552                 0.27675370
## Volume                            -0.149200679                -0.09040334
##                             ProductTypeSmartphone ProductTypeSoftware
## ProductTypeAccessories               -0.159188978        -0.197582993
## ProductTypeDisplay                   -0.059234888        -0.073521462
## ProductTypeExtendedWarranty          -0.086710997        -0.107624401
## ProductTypeGameConsole               -0.036735918        -0.045596075
## ProductTypeLaptop                    -0.045283341        -0.056205010
## ProductTypeNetbook                   -0.036735918        -0.045596075
## ProductTypePC                        -0.052631579        -0.065325533
## ProductTypePrinter                   -0.096373885        -0.119617833
## ProductTypePrinterSupplies           -0.045283341        -0.056205010
## ProductTypeSmartphone                 1.000000000        -0.065325533
## ProductTypeSoftware                  -0.065325533         1.000000000
## ProductTypeTablet                    -0.045283341        -0.056205010
## ProductNum                            0.431369468        -0.214914072
## Price                                 0.001358954        -0.058780827
## x5StarReviews                        -0.038508275         0.001196472
## x4StarReviews                        -0.073264624         0.154461169
## x3StarReviews                        -0.054335058         0.234863478
## x2StarReviews                        -0.037891166         0.350735807
## x1StarReviews                        -0.031436074         0.393364234
## PositiveServiceReview                -0.093917237        -0.041827585
## NegativeServiceReview                -0.056081857         0.406129939
## Recommendproduct                     -0.023391813        -0.065325533
## ShippingWeight                       -0.133107177        -0.167879959
## ProductDepth                         -0.074189350        -0.071848214
## ProductWidth                         -0.110745236        -0.183007483
## ProductHeight                        -0.196337600        -0.129304214
## ProfitMargin                         -0.053555434         0.091501867
## Volume                               -0.038508275         0.001196472
##                             ProductTypeTablet   ProductNum        Price
## ProductTypeAccessories           -0.136963567 -0.338862490 -0.384906124
## ProductTypeDisplay               -0.050964719  0.084073899  0.231729810
## ProductTypeExtendedWarranty      -0.074604710 -0.086078971 -0.097802784
## ProductTypeGameConsole           -0.031606977  0.340268975 -0.015543759
## ProductTypeLaptop                -0.038961039 -0.187367237  0.296140664
## ProductTypeNetbook               -0.031606977  0.222726991  0.055870610
## ProductTypePC                    -0.045283341 -0.263830575  0.547112596
## ProductTypePrinter               -0.082918499  0.249589095 -0.037212288
## ProductTypePrinterSupplies       -0.038961039 -0.093250185 -0.114773627
## ProductTypeSmartphone            -0.045283341  0.431369468  0.001358954
## ProductTypeSoftware              -0.056205010 -0.214914072 -0.058780827
## ProductTypeTablet                 1.000000000  0.332753315  0.131659520
## ProductNum                        0.332753315  1.000000000 -0.039748728
## Price                             0.131659520 -0.039748728  1.000000000
## x5StarReviews                    -0.050941908  0.166120763 -0.142343990
## x4StarReviews                    -0.002433448  0.119400607 -0.165283699
## x3StarReviews                     0.005639815  0.090200642 -0.150537613
## x2StarReviews                    -0.013498120 -0.004533099 -0.110681189
## x1StarReviews                    -0.026603829 -0.063063850 -0.083957332
## PositiveServiceReview            -0.081913925 -0.057748062 -0.142143291
## NegativeServiceReview            -0.049409024 -0.019427155 -0.060790373
## Recommendproduct                  0.088889522  0.003886211  0.068930357
## ShippingWeight                   -0.098414265  0.081238782  0.416777401
## ProductDepth                     -0.036157465  0.036187970  0.010967649
## ProductWidth                      0.039281194  0.126793427  0.382397533
## ProductHeight                    -0.170078975 -0.046220225  0.294160597
## ProfitMargin                      0.026452306  0.039715141  0.099669405
## Volume                           -0.050941908  0.166120763 -0.142343990
##                             x5StarReviews x4StarReviews x3StarReviews
## ProductTypeAccessories        0.127803771  0.1567151258   0.110608918
## ProductTypeDisplay           -0.037583856 -0.0029383203  -0.038495398
## ProductTypeExtendedWarranty   0.070865276 -0.0994666496  -0.099344457
## ProductTypeGameConsole        0.388298241  0.3446366067   0.258709076
## ProductTypeLaptop            -0.069799582 -0.0529742995  -0.045679827
## ProductTypeNetbook           -0.070010545 -0.0801798318  -0.058741337
## ProductTypePC                -0.102891676 -0.1222164888  -0.100934593
## ProductTypePrinter           -0.149200679 -0.1331591777  -0.121109706
## ProductTypePrinterSupplies   -0.090403335 -0.1110026840  -0.094861150
## ProductTypeSmartphone        -0.038508275 -0.0732646241  -0.054335058
## ProductTypeSoftware           0.001196472  0.1544611686   0.234863478
## ProductTypeTablet            -0.050941908 -0.0024334484   0.005639815
## ProductNum                    0.166120763  0.1194006067   0.090200642
## Price                        -0.142343990 -0.1652836990  -0.150537613
## x5StarReviews                 1.000000000  0.8790063940   0.763373189
## x4StarReviews                 0.879006394  1.0000000000   0.937214175
## x3StarReviews                 0.763373189  0.9372141751   1.000000000
## x2StarReviews                 0.487279328  0.6790056214   0.861480050
## x1StarReviews                 0.255023904  0.4449417168   0.679276158
## PositiveServiceReview         0.622260219  0.4834212832   0.418517393
## NegativeServiceReview         0.309418989  0.5332221777   0.684096619
## Recommendproduct              0.169541264  0.0714153315  -0.056613257
## ShippingWeight               -0.188023980 -0.1949140938  -0.171842042
## ProductDepth                  0.066105249 -0.0317207111  -0.049376503
## ProductWidth                 -0.143436609 -0.0006476125  -0.018838926
## ProductHeight                -0.160004003 -0.0858559708  -0.068081406
## ProfitMargin                 -0.013448603 -0.1466538020  -0.128706922
## Volume                        1.000000000  0.8790063940   0.763373189
##                             x2StarReviews x1StarReviews PositiveServiceReview
## ProductTypeAccessories        0.033055555  -0.041647041           0.002699224
## ProductTypeDisplay           -0.027086357  -0.036284641          -0.094384206
## ProductTypeExtendedWarranty  -0.093483762  -0.051893064           0.627109511
## ProductTypeGameConsole        0.074429824   0.003300983          -0.014267327
## ProductTypeLaptop            -0.038007390  -0.021994035          -0.085716506
## ProductTypeNetbook           -0.043114035  -0.028198592          -0.077506288
## ProductTypePC                -0.069310042  -0.042872993          -0.109385958
## ProductTypePrinter           -0.087025567  -0.060204072          -0.184785826
## ProductTypePrinterSupplies   -0.058191494  -0.038660213          -0.096490485
## ProductTypeSmartphone        -0.037891166  -0.031436074          -0.093917237
## ProductTypeSoftware           0.350735807   0.393364234          -0.041827585
## ProductTypeTablet            -0.013498120  -0.026603829          -0.081913925
## ProductNum                   -0.004533099  -0.063063850          -0.057748062
## Price                        -0.110681189  -0.083957332          -0.142143291
## x5StarReviews                 0.487279328   0.255023904           0.622260219
## x4StarReviews                 0.679005621   0.444941717           0.483421283
## x3StarReviews                 0.861480050   0.679276158           0.418517393
## x2StarReviews                 1.000000000   0.951912978           0.308901370
## x1StarReviews                 0.951912978   1.000000000           0.200035288
## PositiveServiceReview         0.308901370   0.200035288           1.000000000
## NegativeServiceReview         0.864754808   0.884728323           0.265549747
## Recommendproduct             -0.197917979  -0.246092974           0.232828810
## ShippingWeight               -0.128685586  -0.095656192          -0.270738543
## ProductDepth                 -0.042636007  -0.034639801          -0.050526592
## ProductWidth                 -0.065799979  -0.101139826          -0.339093728
## ProductHeight                -0.013774805   0.002517859          -0.314294445
## ProfitMargin                 -0.090093715  -0.031227760           0.423591716
## Volume                        0.487279328   0.255023904           0.622260219
##                             NegativeServiceReview Recommendproduct
## ProductTypeAccessories               -0.148034357      0.058505351
## ProductTypeDisplay                   -0.018617554      0.072398196
## ProductTypeExtendedWarranty           0.015288441      0.144518328
## ProductTypeGameConsole                0.081949267      0.126534828
## ProductTypeLaptop                     0.052417536     -0.011740126
## ProductTypeNetbook                   -0.047592529     -0.363277411
## ProductTypePC                        -0.088359185      0.093567251
## ProductTypePrinter                    0.008126681     -0.149914932
## ProductTypePrinterSupplies           -0.081808383     -0.078826557
## ProductTypeSmartphone                -0.056081857     -0.023391813
## ProductTypeSoftware                   0.406129939     -0.065325533
## ProductTypeTablet                    -0.049409024      0.088889522
## ProductNum                           -0.019427155      0.003886211
## Price                                -0.060790373      0.068930357
## x5StarReviews                         0.309418989      0.169541264
## x4StarReviews                         0.533222178      0.071415331
## x3StarReviews                         0.684096619     -0.056613257
## x2StarReviews                         0.864754808     -0.197917979
## x1StarReviews                         0.884728323     -0.246092974
## PositiveServiceReview                 0.265549747      0.232828810
## NegativeServiceReview                 1.000000000     -0.188329242
## Recommendproduct                     -0.188329242      1.000000000
## ShippingWeight                       -0.111793874     -0.126043887
## ProductDepth                         -0.067410452      0.090358266
## ProductWidth                         -0.097207127      0.011091086
## ProductHeight                        -0.020735305     -0.043715755
## ProfitMargin                          0.042035630      0.095760642
## Volume                                0.309418989      0.169541264
##                             ShippingWeight ProductDepth  ProductWidth
## ProductTypeAccessories        -0.341367875  0.191398963 -0.1544624673
## ProductTypeDisplay             0.103740595  0.015283953  0.2844712255
## ProductTypeExtendedWarranty   -0.236802620 -0.157071240 -0.4364044058
## ProductTypeGameConsole        -0.006072795 -0.019260720  0.0220142711
## ProductTypeLaptop             -0.055573162 -0.005033888 -0.0423319723
## ProductTypeNetbook            -0.060059077 -0.031923597  0.0622121883
## ProductTypePC                  0.317383148  0.054011618  0.2021125967
## ProductTypePrinter             0.757676417  0.029243566  0.5559815049
## ProductTypePrinterSupplies    -0.072727018 -0.066864039 -0.1841834287
## ProductTypeSmartphone         -0.133107177 -0.074189350 -0.1107452361
## ProductTypeSoftware           -0.167879959 -0.071848214 -0.1830074830
## ProductTypeTablet             -0.098414265 -0.036157465  0.0392811944
## ProductNum                     0.081238782  0.036187970  0.1267934273
## Price                          0.416777401  0.010967649  0.3823975328
## x5StarReviews                 -0.188023980  0.066105249 -0.1434366092
## x4StarReviews                 -0.194914094 -0.031720711 -0.0006476125
## x3StarReviews                 -0.171842042 -0.049376503 -0.0188389256
## x2StarReviews                 -0.128685586 -0.042636007 -0.0657999794
## x1StarReviews                 -0.095656192 -0.034639801 -0.1011398264
## PositiveServiceReview         -0.270738543 -0.050526592 -0.3390937285
## NegativeServiceReview         -0.111793874 -0.067410452 -0.0972071272
## Recommendproduct              -0.126043887  0.090358266  0.0110910859
## ShippingWeight                 1.000000000  0.065596924  0.6924735181
## ProductDepth                   0.065596924  1.000000000 -0.0060085117
## ProductWidth                   0.692473518 -0.006008512  1.0000000000
## ProductHeight                  0.700311109  0.025484993  0.5668271129
## ProfitMargin                  -0.079215379 -0.207176026 -0.2914363968
## Volume                        -0.188023980  0.066105249 -0.1434366092
##                             ProductHeight ProfitMargin       Volume
## ProductTypeAccessories       -0.060521774 -0.626935212  0.127803771
## ProductTypeDisplay            0.184865930  0.039066904 -0.037583856
## ProductTypeExtendedWarranty  -0.345552857  0.802267233  0.070865276
## ProductTypeGameConsole       -0.041136327 -0.006230125  0.388298241
## ProductTypeLaptop            -0.075600667 -0.081632386 -0.069799582
## ProductTypeNetbook           -0.117742467 -0.061609018 -0.070010545
## ProductTypePC                 0.349917345 -0.023802415 -0.102891676
## ProductTypePrinter            0.515703796 -0.055691552 -0.149200679
## ProductTypePrinterSupplies   -0.074735657  0.276753698 -0.090403335
## ProductTypeSmartphone        -0.196337600 -0.053555434 -0.038508275
## ProductTypeSoftware          -0.129304214  0.091501867  0.001196472
## ProductTypeTablet            -0.170078975  0.026452306 -0.050941908
## ProductNum                   -0.046220225  0.039715141  0.166120763
## Price                         0.294160597  0.099669405 -0.142343990
## x5StarReviews                -0.160004003 -0.013448603  1.000000000
## x4StarReviews                -0.085855971 -0.146653802  0.879006394
## x3StarReviews                -0.068081406 -0.128706922  0.763373189
## x2StarReviews                -0.013774805 -0.090093715  0.487279328
## x1StarReviews                 0.002517859 -0.031227760  0.255023904
## PositiveServiceReview        -0.314294445  0.423591716  0.622260219
## NegativeServiceReview        -0.020735305  0.042035630  0.309418989
## Recommendproduct             -0.043715755  0.095760642  0.169541264
## ShippingWeight                0.700311109 -0.079215379 -0.188023980
## ProductDepth                  0.025484993 -0.207176026  0.066105249
## ProductWidth                  0.566827113 -0.291436397 -0.143436609
## ProductHeight                 1.000000000 -0.288106289 -0.160004003
## ProfitMargin                 -0.288106289  1.000000000 -0.013448603
## Volume                       -0.160004003 -0.013448603  1.000000000

x5starreviews x3starreview x2starreviews x1StarReviews PositiveServiceReview NegativeServiceReview ## our desicision is using coefficent greater than 0.2

corrplot(corrData)

corrplot(corrData, method = "ellipse",
         tl.cex = 0.5,
         order = "hclust",
         addrect = 2, 
         diag = FALSE)

8 Exploratory Data Analysis

##Univarate Analysis x5starreviews x3starreview x2starreviews x1StarReviews PositiveServiceReview NegativeServiceReview

c <- ggplot(sales, aes(ProductType))
c + geom_bar(fill = "steelblue") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Product Type Distribution", x = "Product Type", y = "Count")

* Product Type Distribution: The dataset was dominated by a few key product types likes Accessories, Pc, Netbook and Smartphone

8.1 BIvarate Analysis

d <- ggplot(sales, aes(Price, ProductType))
d + geom_col(fill = "steelblue")

f1 <- ggplot(sales, aes(ProductType, PositiveServiceReview))
f1 + geom_col(fill = "steelblue") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Product Type Distribution", x = "Product Type", y = "Count")

f2 <- ggplot(sales, aes(ProductType, NegativeServiceReview))
f2 + geom_col(fill = "steelblue") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Product Type Distribution", x = "Product Type", y = "Count")

f3 <- ggplot(sales, aes(ProductType, PositiveServiceReview))
f3 + geom_col(fill = "steelblue") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Product Type Distribution", x = "Product Type", y = "Count")

f4 <- ggplot(sales, aes(ProductType, x5StarReviews))
f4 + geom_col(fill = "steelblue") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Product Type Distribution", x = "Product Type", y = "Count")

f5 <- ggplot(sales, aes(x5StarReviews, Volume))
f5 + geom_quantile()
## Smoothing formula not specified. Using: y ~ x

f6 <- ggplot(sales, aes(Volume, Price))
f6 + geom_quantile()  
## Smoothing formula not specified. Using: y ~ x

Mutlitivirate

#boxplot of Product type and Volume
ggplot (sales,aes (x=Price, y=Volume, col=ProductType)) +
geom_point() +
geom_smooth() +
  labs( X = 'Age', Y = "Salary", title= "Multivariate Relationship between Age, salary and Brand")

ggplot(sales, aes(x = ProductType, y = Volume, fill = Price)) +
  geom_boxplot(outlier.color = "red", alpha = 0.7) +
  scale_fill_viridis_c(option = "plasma") +  # beautiful color scale for Price
  labs(
    title = "Distribution of Volume by Product Type and Price",
    x = "Product Type",
    y = "Volume",
    fill = "Price"
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    plot.title = element_text(face = "bold", hjust = 0.5)
  )

# 📈 Scatter + Smooth: ProductType vs Volume, color by Price
ggplot(sales, aes(x = ProductType, y = Volume, color = Price)) +
  geom_jitter(width = 0.2, alpha = 0.7, size = 3) +
  geom_smooth(aes(group = 1), method = "loess", se = FALSE, color = "black") +
  scale_color_viridis_c(option = "inferno") +
  labs(
    title = "Relationship between Product Type, Volume, and Price",
    x = "Product Type",
    y = "Volume",
    color = "Price"
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    plot.title = element_text(face = "bold", hjust = 0.5)
  )
## `geom_smooth()` using formula = 'y ~ x'

ggplot(sales, aes(x = as.factor(ProductType), y = Volume, fill = Price)) +
  geom_boxplot(outlier.color = "red", alpha = 0.7) +
  scale_fill_viridis_c(option = "plasma") +
  labs(
    title = "Distribution of Volume by Product Type and Price",
    x = "Product Type",
    y = "Volume",
    fill = "Price"
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    plot.title = element_text(face = "bold", hjust = 0.5)
  )
## Warning: The following aesthetics were dropped during statistical transformation: fill.
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?

#Exploratory Data Analysis (EDA)

  1. Product Type Distribution: The dataset was dominated by a few key product types (Accessories, Extended Warranty and Software).
  2. Review Scores: Higher numbers of 5-star and positive service reviews were associated with greater sales volumes.
  3. Negative Reviews: Products with higher negative reviews tended to have lower sales.
  4. Price Relationship: Price showed a moderate positive relationship with sales volume, indicating that more expensive items sometimes sold more, possibly due to higher quality or brand reputation.

9 Predictive Modeling

9.1 Spliiting the data

set.seed(3456)
trainIndex <- createDataPartition(sales$Volume, p = .8, 
                                  list = FALSE, 
                                  times = 1)
head(trainIndex)
##      Resample1
## [1,]         1
## [2,]         3
## [3,]         4
## [4,]         5
## [5,]         6
## [6,]         7
trainset <- sales[trainIndex,]
testset <- sales[-trainIndex,]
trainset
##         ProductType ProductNum   Price x5StarReviews x4StarReviews
## 1                PC        101  949.00             3             3
## 3                PC        103  399.00             3             0
## 4            Laptop        104  409.99            49            19
## 5            Laptop        105 1079.99            58            31
## 6       Accessories        106  114.22            83            30
## 7       Accessories        107  379.99            11             3
## 8       Accessories        108   65.29            33            19
## 9       Accessories        109  119.99            16             9
## 12      Accessories        112   15.00            75            25
## 13      Accessories        113   52.50            10             8
## 14      Accessories        114   21.08           313            62
## 16      Accessories        116    3.60             8             6
## 17      Accessories        117    3.60            11             5
## 18      Accessories        118  174.99           170           100
## 19      Accessories        119    9.99            15            12
## 21         Software        121  133.08            34            15
## 22         Software        122  124.99           394           187
## 23         Software        123   56.99           513           217
## 24         Software        124   48.50            29            18
## 26          Display        126  179.99           306           114
## 27          Printer        127  396.35             8             0
## 29  PrinterSupplies        129   83.11             0             0
## 31  PrinterSupplies        131   43.22             5             0
## 32 ExtendedWarranty        132   79.98             0             1
## 33 ExtendedWarranty        133   87.98             5             0
## 34 ExtendedWarranty        134  124.98           308            27
## 35 ExtendedWarranty        135  129.98           308            27
## 36 ExtendedWarranty        136  134.98           308            27
## 37 ExtendedWarranty        137  151.98           308            27
## 38 ExtendedWarranty        138  169.98           308            27
## 39 ExtendedWarranty        139  179.98           308            27
## 40 ExtendedWarranty        140  189.50           308            27
## 41 ExtendedWarranty        141  349.99           308            27
## 42               PC        142  609.99            21             7
## 43           Laptop        143  770.60            22            14
## 44      Accessories        144    3.84            92            29
## 46      Accessories        146   59.99           366            59
## 47      Accessories        147   38.66           209            83
## 49      Accessories        149  126.95            13             2
## 50      Accessories        150   49.99          2801           431
## 51      Accessories        151  103.85             3             0
## 52      Accessories        152   52.72            51            33
## 54      Accessories        154   16.24           108            54
## 55      Accessories        155   69.00           226            37
## 56          Display        156  359.99            90            27
## 57          Display        157 1276.57           164            33
## 58          Display        158  783.98            26            13
## 59          Display        159  149.99            21            10
## 60          Printer        160  129.99            74            25
## 61          Printer        161  128.49            58            33
## 62          Printer        162  141.95             4             0
## 63          Printer        163  149.99             8             3
## 64          Printer        164  165.99             2             0
## 65          Printer        165  169.26            20            13
## 66          Printer        166  132.36             0             1
## 67          Printer        167  149.99           206            89
## 68          Printer        168  395.00             8             0
## 70          Netbook        177  379.99             1             0
## 73      GameConsole        198  129.00          1759           296
## 74           Tablet        188  499.00            86            51
## 75           Tablet        189  419.00             3             1
## 77       Smartphone        192   99.00            18            17
## 78          Netbook        182  349.99            22            10
## 79       Smartphone        197  499.00           368            28
## 80      GameConsole        200  299.99           421            87
##    x3StarReviews x2StarReviews x1StarReviews PositiveServiceReview
## 1              2             0             0                     2
## 3              0             0             0                     1
## 4              8             3             9                     7
## 5             11             7            36                     7
## 6             10             9            40                    12
## 7              0             0             1                     3
## 8             12             5             9                     5
## 9              2             0             2                     2
## 12             6             3             3                     9
## 13             5             0             1                     2
## 14            13             8            16                    44
## 16             3             2             1                     0
## 17             2             2             1                     0
## 18            23            20            20                   310
## 19             4             0             4                     3
## 21             2             2            10                     5
## 22            63            42            86                    55
## 23           162           370          1654                   144
## 24             3             1             8                     4
## 26            25            22            28                    42
## 27             1             0             2                     1
## 29             0             1             3                     1
## 31             0             0             0                     1
## 32             1             1             1                     0
## 33             2             0             1                     0
## 34             8             3            15                   280
## 35             8             3            15                   280
## 36             8             3            15                   280
## 37             8             3            15                   280
## 38             8             3            15                   280
## 39             8             3            15                   280
## 40             8             3            15                   280
## 41             8             3            15                   280
## 42             3             0            12                     5
## 43             4             5             6                     6
## 44             8             4            10                    12
## 46            23            26            24                    60
## 47            35            38            36                    15
## 49             2             2             5                     5
## 50           157           154           270                   536
## 51             0             0             0                     1
## 52             8             7             4                     6
## 54            12             2             6                     7
## 55             3             7             8                    13
## 56            10             4             4                     7
## 57             6            13             6                    12
## 58             7             5            16                     4
## 59             3             1             4                     4
## 60             7             6             9                     4
## 61            10             3             6                     5
## 62             0             0             3                     0
## 63             3             2             0                     0
## 64             1             1             2                     1
## 65             8             6            21                     4
## 66             0             0             0                     0
## 67            20            22            65                    42
## 68             1             0             2                     3
## 70             1             1             0                     0
## 73           109            56            44                    56
## 74            17            12             9                    14
## 75             0             0             0                     0
## 77             6             2            12                     5
## 78             6             2            10                     3
## 79            14            10            23                    22
## 80            20            14            39                    29
##    NegativeServiceReview Recommendproduct ShippingWeight ProductDepth
## 1                      0              0.9          25.80        23.94
## 3                      0              0.9          17.40        10.50
## 4                      8              0.8           5.70        15.00
## 5                     20              0.7           7.00        12.90
## 6                      5              0.3           1.60         5.80
## 7                      0              0.9           7.30         6.70
## 8                      3              0.7          12.00         7.90
## 9                      1              0.8           1.80        10.60
## 12                     2              0.2           2.20        21.30
## 13                     0              0.8           1.10        15.60
## 14                     3              0.9           0.35         5.70
## 16                     0              0.8           0.01        11.50
## 17                     0              0.8           0.01        11.50
## 18                     6              0.8           1.40        13.80
## 19                     1              0.8           0.40        11.10
## 21                     4              0.7           3.20         7.40
## 22                    38              0.8           0.15         7.60
## 23                   112              0.3           0.55         5.20
## 24                     2              0.8           0.20         8.00
## 26                    12              0.8          13.70         8.50
## 27                     1              0.3          63.00        17.90
## 29                     1              0.1          10.30         0.00
## 31                     0              1.0           1.00         4.70
## 32                     3              0.4           0.20         0.00
## 33                     1              0.6           0.20         0.00
## 34                     8              0.9           0.20         0.00
## 35                     8              0.9           0.20         0.00
## 36                     8              0.9           0.20         0.00
## 37                     8              0.9           0.20         0.00
## 38                     8              0.9           0.20         0.00
## 39                     8              0.9           0.20         0.00
## 40                     8              0.9           0.20         0.00
## 41                     8              0.9           0.20         0.00
## 42                     3              0.6          29.10        20.95
## 43                     2              0.7           3.54        12.72
## 44                     3              0.8           1.00         6.50
## 46                     5              0.8           2.40         7.90
## 47                     4              0.7           0.40         3.60
## 49                     1              0.6           3.00         5.90
## 50                    22              0.8           0.40         7.00
## 51                     0              0.9           8.00         4.80
## 52                     1              0.8           4.00         6.60
## 54                     3              0.9           0.55         6.00
## 55                     1              0.9           3.80        15.00
## 56                     3              0.9           7.00         9.20
## 57                     4              0.9          23.00        15.50
## 58                     5              0.6          25.00        29.20
## 59                     2              0.8          10.00        20.00
## 60                     2              0.9          32.20        15.70
## 61                     2              0.9          22.70        15.70
## 62                     1              0.5          25.00        19.50
## 63                     0              0.7          35.00        10.20
## 64                     1              0.5          31.00        22.10
## 65                     7              0.5          32.00        15.10
## 66                     0              0.8          30.20        20.90
## 67                    50              0.7          13.00         8.80
## 68                     0              0.8          63.00        17.90
## 70                     1              0.3           3.00         7.44
## 73                    13              0.9           7.25         8.50
## 74                     2              0.8           2.00        10.10
## 75                     0              0.9           2.20         7.00
## 77                     4              0.7           0.70         2.80
## 78                     3              0.3           5.00         7.57
## 79                     3              0.9           0.90         2.70
## 80                    14              0.9          10.94        12.00
##    ProductWidth ProductHeight ProfitMargin Volume
## 1          6.62         16.89         0.15     12
## 3          8.30         10.20         0.08     12
## 4          9.90          1.30         0.08    196
## 5          0.30          8.90         0.09    232
## 6          4.00          1.00         0.05    332
## 7         10.30         11.50         0.05     44
## 8          6.70          2.20         0.05    132
## 9          9.40          4.70         0.05     64
## 12         1.80          7.80         0.05    300
## 13         3.00         15.00         0.05     40
## 14         3.50          8.30         0.05   1252
## 16         8.50          0.40         0.05     32
## 17         8.50          0.40         0.05     44
## 18         8.20          0.40         0.05    680
## 19         7.60          0.50         0.05     60
## 21         5.50          1.40         0.15    136
## 22         5.50          1.20         0.20   1576
## 23         1.40          7.50         0.15   2052
## 24         7.00          1.00         0.20    116
## 26        22.30         17.50         0.08   1224
## 27        15.90         12.70         0.12     32
## 29         0.00          0.00         0.35      0
## 31         2.90          6.30         0.30     20
## 32         0.00          0.00         0.40      0
## 33         0.00          0.00         0.40     20
## 34         0.00          0.00         0.40   1232
## 35         0.00          0.00         0.40   1232
## 36         0.00          0.00         0.40   1232
## 37         0.00          0.00         0.40   1232
## 38         0.00          0.00         0.40   1232
## 39         0.00          0.00         0.40   1232
## 40         0.00          0.00         0.40   1232
## 41         0.00          0.00         0.40   1232
## 42         8.47         20.71         0.09     84
## 43         8.90          0.71         0.15     88
## 44         4.20          1.50         0.05    368
## 46         1.40         19.10         0.05   1464
## 47         6.50          8.80         0.05    836
## 49         1.80          6.70         0.05     52
## 50         4.50          1.20         0.05  11204
## 51         1.30          4.80         0.05     12
## 52         5.50          5.20         0.05    204
## 54         3.00          8.20         0.05    432
## 55         9.80         18.90         0.05    904
## 56        11.20          3.20         0.20    360
## 57        17.70          5.70         0.25    656
## 58         9.90         23.00         0.16    104
## 59        15.30          6.40         0.17     84
## 60        15.90         12.40         0.10    296
## 61        15.90         10.60         0.12    232
## 62        18.00         14.00         0.14     16
## 63        15.98         14.55         0.18     32
## 64        18.60         13.50         0.18      8
## 65        11.70         19.60         0.16     80
## 66        20.90         14.60         0.20      0
## 67        13.70          7.60         0.15    824
## 68        15.90         12.70         0.09     32
## 70        10.43          1.02         0.10      4
## 73         6.00          1.75         0.18   7036
## 74         6.90          0.38         0.20    344
## 75        10.20          0.40         0.18     12
## 77         5.30          0.40         0.17     72
## 78        10.47          1.43         0.12     88
## 79         5.00          0.40         0.10   1472
## 80        11.50          7.25         0.12   1684
testset
##        ProductType ProductNum   Price x5StarReviews x4StarReviews x3StarReviews
## 2               PC        102 2249.99             2             1             0
## 10     Accessories        110   16.99            10             1             1
## 11     Accessories        111    6.55            21             2             2
## 15     Accessories        115   18.98           349           118            27
## 20        Software        120  670.00            20             2             4
## 25        Software        125   31.99            77            31             7
## 28         Printer        128  262.98            22             8             3
## 30 PrinterSupplies        130   26.78             6             2             0
## 45     Accessories        145    6.99           384            31            13
## 48     Accessories        148   10.75           535           261           134
## 53     Accessories        153   19.99           474            38             7
## 69         Printer        169  385.96            99            43            17
## 71          Tablet        185  499.00           148            66            30
## 72      Smartphone        190  199.00             4             1             0
## 76      Smartphone        191  200.00            62            25            10
##    x2StarReviews x1StarReviews PositiveServiceReview NegativeServiceReview
## 2              0             0                     1                     0
## 10             0             0                     2                     0
## 11             4            15                     2                     1
## 15             7             5                    57                     3
## 20             2             4                     4                     3
## 25             3             2                     7                     0
## 28             1             3                     5                     1
## 30             0             1                     1                     0
## 45             5            20                    50                     1
## 48           104           177                   120                    15
## 53             6            12                    80                     2
## 69            11            20                     8                    13
## 71            20            29                    12                     6
## 72             2             2                     1                     1
## 76            11            12                     9                     3
##    Recommendproduct ShippingWeight ProductDepth ProductWidth ProductHeight
## 2               0.9          50.00         35.0        31.75          19.0
## 10              0.9           0.75         10.7        13.10           0.6
## 11              0.5           1.00          7.3         7.00           1.6
## 15              0.9           0.60          1.7        13.50          10.2
## 20              0.7           0.25          5.8         1.40           7.8
## 25              0.9           0.20          0.0         0.00           0.0
## 28              0.8          57.00         17.3        23.50          25.8
## 30              0.9           1.00          3.3         1.60           4.7
## 45              0.9           1.00        108.0         0.50           0.5
## 48              0.7           1.50         11.5        20.00           7.2
## 53              0.9           1.50        300.0         0.50           0.5
## 69              0.7          39.00         21.0        15.40          17.9
## 71              0.8           2.20          7.1        10.40           0.3
## 72              0.5           1.10          4.5         2.50           0.5
## 76              0.8           0.90          2.8         5.40           0.3
##    ProfitMargin Volume
## 2          0.25      8
## 10         0.05     40
## 11         0.05     84
## 15         0.05   1396
## 20         0.15     80
## 25         0.30    308
## 28         0.12     88
## 30         0.30     24
## 45         0.05   1536
## 48         0.05   2140
## 53         0.05   1896
## 69         0.11    396
## 71         0.13    592
## 72         0.10     16
## 76         0.14    248

9.2 Creating/building your model

## base parameter tuning  
fitControl <- trainControl(## 10-fold CV
                           method = "repeatedcv",
                           number = 10,
                           ## repeated ten times
                           repeats = 10)

x5starreviews x3starreview x2starreviews x1StarReviews PositiveServiceReview NegativeServiceReview

9.3 gbm method

gbmFit1 <- train(Volume ~ x5StarReviews + x3StarReviews + x2StarReviews 
+ x1StarReviews + PositiveServiceReview + NegativeServiceReview
 , data = trainset, 
                 method = "gbm", 
                 trControl = fitControl,
                 ## This last option is actually one
                 ## for gbm() that passes through
                 verbose = FALSE)
gbmFit1
## Stochastic Gradient Boosting 
## 
## 65 samples
##  6 predictor
## 
## No pre-processing
## Resampling: Cross-Validated (10 fold, repeated 10 times) 
## Summary of sample sizes: 57, 58, 58, 58, 61, 59, ... 
## Resampling results across tuning parameters:
## 
##   interaction.depth  n.trees  RMSE      Rsquared   MAE     
##   1                   50      916.8905  0.8596902  522.4417
##   1                  100      954.0825  0.8403375  547.6375
##   1                  150      966.5379  0.8213587  550.6749
##   2                   50      934.8810  0.8554955  527.9830
##   2                  100      955.7133  0.8306530  544.3705
##   2                  150      986.1560  0.8051720  566.7482
##   3                   50      904.2145  0.8537386  508.6439
##   3                  100      948.9077  0.8335186  545.6307
##   3                  150      981.9606  0.8127440  568.1245
## 
## Tuning parameter 'shrinkage' was held constant at a value of 0.1
## 
## Tuning parameter 'n.minobsinnode' was held constant at a value of 10
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were n.trees = 50, interaction.depth =
##  3, shrinkage = 0.1 and n.minobsinnode = 10.

9.4 Random forest method

rfFit1 <- train(Volume ~ x5StarReviews + x3StarReviews + x2StarReviews 
+ x1StarReviews + PositiveServiceReview + NegativeServiceReview
 , data = trainset,  
                 method = "rf", 
                 trControl = fitControl,
                 ## This last option is actually one
                 ## for rf() that passes through
                 verbose = FALSE)
rfFit1
## Random Forest 
## 
## 65 samples
##  6 predictor
## 
## No pre-processing
## Resampling: Cross-Validated (10 fold, repeated 10 times) 
## Summary of sample sizes: 60, 59, 59, 59, 58, 58, ... 
## Resampling results across tuning parameters:
## 
##   mtry  RMSE      Rsquared   MAE     
##   2     696.7254  0.9359943  324.1327
##   4     615.2925  0.9625367  275.2524
##   6     572.5526  0.9710869  250.6320
## 
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was mtry = 6.

9.5 pls method

plsFit1 <- train(Volume ~ x5StarReviews + x3StarReviews + x2StarReviews 
+ x1StarReviews + PositiveServiceReview + NegativeServiceReview
 , data = trainset, 
                 method = "pls", 
                 trControl = fitControl,
                 ## This last option is actually one
                 ## for pls() that passes through
                 verbose = FALSE)
plsFit1
## Partial Least Squares 
## 
## 65 samples
##  6 predictor
## 
## No pre-processing
## Resampling: Cross-Validated (10 fold, repeated 10 times) 
## Summary of sample sizes: 58, 60, 59, 60, 57, 59, ... 
## Resampling results across tuning parameters:
## 
##   ncomp  RMSE       Rsquared   MAE     
##   1      93.141027  0.9960984  58.86613
##   2      64.897129  0.9966117  38.82438
##   3       3.364601  0.9999820   1.85688
## 
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was ncomp = 3.
resamps_volume <- resamples(list(rf = rfFit1, gbm = gbmFit1, pls = plsFit1))
summary(resamps_volume)
## 
## Call:
## summary.resamples(object = resamps_volume)
## 
## Models: rf, gbm, pls 
## Number of resamples: 100 
## 
## MAE 
##            Min.     1st Qu.     Median      Mean    3rd Qu.       Max. NA's
## rf    3.0555733  20.3064097  44.354892 250.63197 410.350757 2174.86328    0
## gbm 110.7378056 278.3536243 360.055542 508.64387 492.145952 2256.35794    0
## pls   0.4171837   0.7542022   1.028837   1.85688   1.904532   11.92195    0
## 
## RMSE 
##            Min.    1st Qu.     Median       Mean    3rd Qu.       Max. NA's
## rf    3.5551550  36.370905  81.172127 572.552568 940.959024 4142.13703    0
## gbm 148.0185869 386.823412 476.928336 904.214479 674.903067 4300.49745    0
## pls   0.5344391   0.846866   1.420012   3.364601   3.275619   27.62494    0
## 
## Rsquared 
##          Min.   1st Qu.    Median      Mean   3rd Qu.      Max. NA's
## rf  0.8202242 0.9714455 0.9874611 0.9710869 0.9968108 0.9999510    0
## gbm 0.4249728 0.8042423 0.8947760 0.8537386 0.9514985 0.9994113    0
## pls 0.9998242 0.9999826 0.9999980 0.9999820 0.9999993 1.0000000    0

9.6 Building finally Model using PLS

plsGrid <-  expand.grid(ncomp = 3)
                        
nrow(plsGrid)
## [1] 1
plsFitfinal <- train(Volume ~ x5StarReviews + x3StarReviews + x2StarReviews 
+ x1StarReviews + PositiveServiceReview + NegativeServiceReview
 , data = trainset, 
                 method = "pls", 
                 trControl = fitControl,
                 ## This last option is actually one
                 ## for pls() that passes through
                 verbose = FALSE,
                 tuneGrid = plsGrid)
plsFitfinal
## Partial Least Squares 
## 
## 65 samples
##  6 predictor
## 
## No pre-processing
## Resampling: Cross-Validated (10 fold, repeated 10 times) 
## Summary of sample sizes: 60, 59, 57, 60, 57, 60, ... 
## Resampling results:
## 
##   RMSE      Rsquared  MAE     
##   3.203816  0.999985  1.799722
## 
## Tuning parameter 'ncomp' was held constant at a value of 3

9.7 Predicting the model

predictionsplsFitfinal <- predict(plsFitfinal , newdata = testset)
predictionsplsFitfinal
##  [1]    7.327051   39.422423   83.281043 1396.720898   80.018309  307.956439
##  [7]   87.686341   23.213916 1532.045493 2166.182325 1890.076936  398.038182
## [13]  596.796547   15.462284  249.462005
## Combine actual and predicted values into one data frame
comparison <- data.frame(
  Actual = testset$Volume,
  Predicted = predictionsplsFitfinal)

## Scatter plot using ggplot2
ggplot(comparison, aes(x = Actual, y = Predicted)) +
  geom_point(color = "blue", alpha = 0.6) +
  geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "red") +
  labs(
    title = "Actual vs Predicted Volume",
    x = "Actual Volume",
    y = "Predicted Volume"
  ) +
  theme_minimal()

#loading of data set ## Loading of the new data set

sales1 <- read.csv("newproductattributes2017.csv")

9.8 Predicting the new model

predictingvolume <- predict(plsFitfinal , newdata = sales1)
predictingvolume
##  [1]  385.5826945  205.0904825  294.7914605   27.5596072    3.9391488
##  [6]   75.6125217 1250.4253010   94.6127325   11.4382344 1186.3213588
## [11] 3814.5910481  396.8606521  407.9357856  167.6647752  202.9814544
## [16] 1844.9857166   15.2064111  119.9590037   99.2140333  115.3320803
## [21]  350.5806813   19.2767932   -0.3358663 6101.2073747
sales_volume <- cbind(sales1, predictingvolume)
sales_volume
##         ProductType ProductNum   Price x5StarReviews x4StarReviews
## 1                PC        171  699.00            96            26
## 2                PC        172  860.00            51            11
## 3            Laptop        173 1199.00            74            10
## 4            Laptop        175 1199.00             7             2
## 5            Laptop        176 1999.00             1             1
## 6           Netbook        178  399.99            19             8
## 7           Netbook        180  329.00           312           112
## 8           Netbook        181  439.00            23            18
## 9           Netbook        183  330.00             3             4
## 10           Tablet        186  629.00           296            66
## 11           Tablet        187  199.00           943           437
## 12       Smartphone        193  199.00            99            26
## 13       Smartphone        194   49.00           100            26
## 14       Smartphone        195  149.00            42             8
## 15       Smartphone        196  300.00            50            19
## 16      GameConsole        199  249.99           462            97
## 17          Display        201  140.00             4             0
## 18      Accessories        301   20.99            30             1
## 19      Accessories        302    8.50            25             2
## 20         Software        303   70.99            29            18
## 21          Printer        304  199.99            88             8
## 22  PrinterSupplies        305   20.99             5             0
## 23 ExtendedWarranty        306   99.99             0             1
## 24      GameConsole        307  425.00          1525           252
##    x3StarReviews x2StarReviews x1StarReviews PositiveServiceReview
## 1             14            14            25                    12
## 2             10            10            21                     7
## 3              3             3            11                    11
## 4              1             1             1                     2
## 5              1             3             0                     0
## 6              4             1            10                     2
## 7             28            31            47                    28
## 8              7            22            18                     5
## 9              0             1             0                     1
## 10            30            21            36                    28
## 11           224           160           247                    90
## 12            12            16            35                     8
## 13            37            33            48                    14
## 14             4             4             9                     4
## 15            13            20            22                     5
## 16            25            17            58                    32
## 17             0             0             2                     1
## 18             5             0             0                     2
## 19             2             4            15                     2
## 20             3             1             8                     4
## 21             3             1             3                     5
## 22             0             0             0                     1
## 23             1             1             1                     0
## 24            99            56            45                    59
##    NegativeServiceReview Recommendproduct BestSellersRank ShippingWeight
## 1                      3              0.7            2498          19.90
## 2                      5              0.6             490          27.00
## 3                      5              0.8             111           6.60
## 4                      1              0.6            4446          13.00
## 5                      1              0.3            2820          11.60
## 6                      4              0.6            4140           5.80
## 7                     16              0.7            2699           4.60
## 8                     16              0.4            1704           4.80
## 9                      0              0.7            5128           4.30
## 10                     9              0.8              34           3.00
## 11                    23              0.8               1           0.90
## 12                     6              0.4            1277           0.90
## 13                     6              0.6           16966           0.70
## 14                     1              0.7            6316           0.80
## 15                     7              0.6           44465           0.90
## 16                    12              0.8             115           8.40
## 17                     1              0.7             324           8.90
## 18                     0              0.9              18           0.75
## 19                     1              0.5              38           1.00
## 20                     2              0.8             122           0.20
## 21                     1              0.8              40          42.00
## 22                     0              1.0            1011           1.00
## 23                     3              0.4               5           0.20
## 24                    13              0.9             215          20.00
##    ProductDepth ProductWidth ProductHeight ProfitMargin Volume predictingvolume
## 1         20.63        19.25          8.39         0.25      0      385.5826945
## 2         21.89        27.01          9.13         0.20      0      205.0904825
## 3          8.94        12.80          0.68         0.10      0      294.7914605
## 4         16.30        10.80          1.40         0.15      0       27.5596072
## 5         16.81        10.90          0.88         0.23      0        3.9391488
## 6          8.43        11.42          1.20         0.08      0       75.6125217
## 7         10.17         7.28          0.95         0.09      0     1250.4253010
## 8          8.00        11.70          1.50         0.11      0       94.6127325
## 9          7.40        10.40          0.97         0.09      0       11.4382344
## 10         7.31         9.50          0.37         0.10      0     1186.3213588
## 11         5.40         7.60          0.40         0.20      0     3814.5910481
## 12         2.70         5.20          0.40         0.11      0      396.8606521
## 13         2.67         5.33          0.37         0.12      0      407.9357856
## 14         2.70         5.30          0.40         0.15      0      167.6647752
## 15         2.60         5.00          0.40         0.11      0      202.9814544
## 16         6.20        13.20         13.20         0.09      0     1844.9857166
## 17        13.60        17.60          7.30         0.05      0       15.2064111
## 18        10.70        13.10          0.60         0.05      0      119.9590037
## 19         7.30         7.00          1.60         0.10      0       99.2140333
## 20         8.00         7.00          1.00         0.20      0      115.3320803
## 21        17.30        23.50         25.80         0.90      0      350.5806813
## 22         4.70         2.90          6.30         0.30      0       19.2767932
## 23         0.00         0.00          0.00         0.40      0       -0.3358663
## 24         8.50         6.00          1.75         0.18      0     6101.2073747

10 remove column by name

sales_volume$Volume <- NULL
colnames(sales_volume)
##  [1] "ProductType"           "ProductNum"            "Price"                
##  [4] "x5StarReviews"         "x4StarReviews"         "x3StarReviews"        
##  [7] "x2StarReviews"         "x1StarReviews"         "PositiveServiceReview"
## [10] "NegativeServiceReview" "Recommendproduct"      "BestSellersRank"      
## [13] "ShippingWeight"        "ProductDepth"          "ProductWidth"         
## [16] "ProductHeight"         "ProfitMargin"          "predictingvolume"
sales_volume
##         ProductType ProductNum   Price x5StarReviews x4StarReviews
## 1                PC        171  699.00            96            26
## 2                PC        172  860.00            51            11
## 3            Laptop        173 1199.00            74            10
## 4            Laptop        175 1199.00             7             2
## 5            Laptop        176 1999.00             1             1
## 6           Netbook        178  399.99            19             8
## 7           Netbook        180  329.00           312           112
## 8           Netbook        181  439.00            23            18
## 9           Netbook        183  330.00             3             4
## 10           Tablet        186  629.00           296            66
## 11           Tablet        187  199.00           943           437
## 12       Smartphone        193  199.00            99            26
## 13       Smartphone        194   49.00           100            26
## 14       Smartphone        195  149.00            42             8
## 15       Smartphone        196  300.00            50            19
## 16      GameConsole        199  249.99           462            97
## 17          Display        201  140.00             4             0
## 18      Accessories        301   20.99            30             1
## 19      Accessories        302    8.50            25             2
## 20         Software        303   70.99            29            18
## 21          Printer        304  199.99            88             8
## 22  PrinterSupplies        305   20.99             5             0
## 23 ExtendedWarranty        306   99.99             0             1
## 24      GameConsole        307  425.00          1525           252
##    x3StarReviews x2StarReviews x1StarReviews PositiveServiceReview
## 1             14            14            25                    12
## 2             10            10            21                     7
## 3              3             3            11                    11
## 4              1             1             1                     2
## 5              1             3             0                     0
## 6              4             1            10                     2
## 7             28            31            47                    28
## 8              7            22            18                     5
## 9              0             1             0                     1
## 10            30            21            36                    28
## 11           224           160           247                    90
## 12            12            16            35                     8
## 13            37            33            48                    14
## 14             4             4             9                     4
## 15            13            20            22                     5
## 16            25            17            58                    32
## 17             0             0             2                     1
## 18             5             0             0                     2
## 19             2             4            15                     2
## 20             3             1             8                     4
## 21             3             1             3                     5
## 22             0             0             0                     1
## 23             1             1             1                     0
## 24            99            56            45                    59
##    NegativeServiceReview Recommendproduct BestSellersRank ShippingWeight
## 1                      3              0.7            2498          19.90
## 2                      5              0.6             490          27.00
## 3                      5              0.8             111           6.60
## 4                      1              0.6            4446          13.00
## 5                      1              0.3            2820          11.60
## 6                      4              0.6            4140           5.80
## 7                     16              0.7            2699           4.60
## 8                     16              0.4            1704           4.80
## 9                      0              0.7            5128           4.30
## 10                     9              0.8              34           3.00
## 11                    23              0.8               1           0.90
## 12                     6              0.4            1277           0.90
## 13                     6              0.6           16966           0.70
## 14                     1              0.7            6316           0.80
## 15                     7              0.6           44465           0.90
## 16                    12              0.8             115           8.40
## 17                     1              0.7             324           8.90
## 18                     0              0.9              18           0.75
## 19                     1              0.5              38           1.00
## 20                     2              0.8             122           0.20
## 21                     1              0.8              40          42.00
## 22                     0              1.0            1011           1.00
## 23                     3              0.4               5           0.20
## 24                    13              0.9             215          20.00
##    ProductDepth ProductWidth ProductHeight ProfitMargin predictingvolume
## 1         20.63        19.25          8.39         0.25      385.5826945
## 2         21.89        27.01          9.13         0.20      205.0904825
## 3          8.94        12.80          0.68         0.10      294.7914605
## 4         16.30        10.80          1.40         0.15       27.5596072
## 5         16.81        10.90          0.88         0.23        3.9391488
## 6          8.43        11.42          1.20         0.08       75.6125217
## 7         10.17         7.28          0.95         0.09     1250.4253010
## 8          8.00        11.70          1.50         0.11       94.6127325
## 9          7.40        10.40          0.97         0.09       11.4382344
## 10         7.31         9.50          0.37         0.10     1186.3213588
## 11         5.40         7.60          0.40         0.20     3814.5910481
## 12         2.70         5.20          0.40         0.11      396.8606521
## 13         2.67         5.33          0.37         0.12      407.9357856
## 14         2.70         5.30          0.40         0.15      167.6647752
## 15         2.60         5.00          0.40         0.11      202.9814544
## 16         6.20        13.20         13.20         0.09     1844.9857166
## 17        13.60        17.60          7.30         0.05       15.2064111
## 18        10.70        13.10          0.60         0.05      119.9590037
## 19         7.30         7.00          1.60         0.10       99.2140333
## 20         8.00         7.00          1.00         0.20      115.3320803
## 21        17.30        23.50         25.80         0.90      350.5806813
## 22         4.70         2.90          6.30         0.30       19.2767932
## 23         0.00         0.00          0.00         0.40       -0.3358663
## 24         8.50         6.00          1.75         0.18     6101.2073747
# rename one column
names(sales_volume)[names(sales_volume) == "predictingvolume"] <- "volume"
sales_volume
##         ProductType ProductNum   Price x5StarReviews x4StarReviews
## 1                PC        171  699.00            96            26
## 2                PC        172  860.00            51            11
## 3            Laptop        173 1199.00            74            10
## 4            Laptop        175 1199.00             7             2
## 5            Laptop        176 1999.00             1             1
## 6           Netbook        178  399.99            19             8
## 7           Netbook        180  329.00           312           112
## 8           Netbook        181  439.00            23            18
## 9           Netbook        183  330.00             3             4
## 10           Tablet        186  629.00           296            66
## 11           Tablet        187  199.00           943           437
## 12       Smartphone        193  199.00            99            26
## 13       Smartphone        194   49.00           100            26
## 14       Smartphone        195  149.00            42             8
## 15       Smartphone        196  300.00            50            19
## 16      GameConsole        199  249.99           462            97
## 17          Display        201  140.00             4             0
## 18      Accessories        301   20.99            30             1
## 19      Accessories        302    8.50            25             2
## 20         Software        303   70.99            29            18
## 21          Printer        304  199.99            88             8
## 22  PrinterSupplies        305   20.99             5             0
## 23 ExtendedWarranty        306   99.99             0             1
## 24      GameConsole        307  425.00          1525           252
##    x3StarReviews x2StarReviews x1StarReviews PositiveServiceReview
## 1             14            14            25                    12
## 2             10            10            21                     7
## 3              3             3            11                    11
## 4              1             1             1                     2
## 5              1             3             0                     0
## 6              4             1            10                     2
## 7             28            31            47                    28
## 8              7            22            18                     5
## 9              0             1             0                     1
## 10            30            21            36                    28
## 11           224           160           247                    90
## 12            12            16            35                     8
## 13            37            33            48                    14
## 14             4             4             9                     4
## 15            13            20            22                     5
## 16            25            17            58                    32
## 17             0             0             2                     1
## 18             5             0             0                     2
## 19             2             4            15                     2
## 20             3             1             8                     4
## 21             3             1             3                     5
## 22             0             0             0                     1
## 23             1             1             1                     0
## 24            99            56            45                    59
##    NegativeServiceReview Recommendproduct BestSellersRank ShippingWeight
## 1                      3              0.7            2498          19.90
## 2                      5              0.6             490          27.00
## 3                      5              0.8             111           6.60
## 4                      1              0.6            4446          13.00
## 5                      1              0.3            2820          11.60
## 6                      4              0.6            4140           5.80
## 7                     16              0.7            2699           4.60
## 8                     16              0.4            1704           4.80
## 9                      0              0.7            5128           4.30
## 10                     9              0.8              34           3.00
## 11                    23              0.8               1           0.90
## 12                     6              0.4            1277           0.90
## 13                     6              0.6           16966           0.70
## 14                     1              0.7            6316           0.80
## 15                     7              0.6           44465           0.90
## 16                    12              0.8             115           8.40
## 17                     1              0.7             324           8.90
## 18                     0              0.9              18           0.75
## 19                     1              0.5              38           1.00
## 20                     2              0.8             122           0.20
## 21                     1              0.8              40          42.00
## 22                     0              1.0            1011           1.00
## 23                     3              0.4               5           0.20
## 24                    13              0.9             215          20.00
##    ProductDepth ProductWidth ProductHeight ProfitMargin       volume
## 1         20.63        19.25          8.39         0.25  385.5826945
## 2         21.89        27.01          9.13         0.20  205.0904825
## 3          8.94        12.80          0.68         0.10  294.7914605
## 4         16.30        10.80          1.40         0.15   27.5596072
## 5         16.81        10.90          0.88         0.23    3.9391488
## 6          8.43        11.42          1.20         0.08   75.6125217
## 7         10.17         7.28          0.95         0.09 1250.4253010
## 8          8.00        11.70          1.50         0.11   94.6127325
## 9          7.40        10.40          0.97         0.09   11.4382344
## 10         7.31         9.50          0.37         0.10 1186.3213588
## 11         5.40         7.60          0.40         0.20 3814.5910481
## 12         2.70         5.20          0.40         0.11  396.8606521
## 13         2.67         5.33          0.37         0.12  407.9357856
## 14         2.70         5.30          0.40         0.15  167.6647752
## 15         2.60         5.00          0.40         0.11  202.9814544
## 16         6.20        13.20         13.20         0.09 1844.9857166
## 17        13.60        17.60          7.30         0.05   15.2064111
## 18        10.70        13.10          0.60         0.05  119.9590037
## 19         7.30         7.00          1.60         0.10   99.2140333
## 20         8.00         7.00          1.00         0.20  115.3320803
## 21        17.30        23.50         25.80         0.90  350.5806813
## 22         4.70         2.90          6.30         0.30   19.2767932
## 23         0.00         0.00          0.00         0.40   -0.3358663
## 24         8.50         6.00          1.75         0.18 6101.2073747
agg <- aggregate(sales_volume$volume, by=list(sales_volume$ProductType), FUN=sum)
agg
##             Group.1            x
## 1       Accessories  219.1730370
## 2           Display   15.2064111
## 3  ExtendedWarranty   -0.3358663
## 4       GameConsole 7946.1930912
## 5            Laptop  326.2902165
## 6           Netbook 1432.0887895
## 7                PC  590.6731770
## 8           Printer  350.5806813
## 9   PrinterSupplies   19.2767932
## 10       Smartphone 1175.4426674
## 11         Software  115.3320803
## 12           Tablet 5000.9124069
colnames(agg) <- c('product', 'volume')
agg
##             product       volume
## 1       Accessories  219.1730370
## 2           Display   15.2064111
## 3  ExtendedWarranty   -0.3358663
## 4       GameConsole 7946.1930912
## 5            Laptop  326.2902165
## 6           Netbook 1432.0887895
## 7                PC  590.6731770
## 8           Printer  350.5806813
## 9   PrinterSupplies   19.2767932
## 10       Smartphone 1175.4426674
## 11         Software  115.3320803
## 12           Tablet 5000.9124069
library(dplyr)
predictedproducttype <- agg %>%
  filter(product %in% c("PC", "Laptop", "Netbook" , "Smartphone"))
predictedproducttype
##      product    volume
## 1     Laptop  326.2902
## 2    Netbook 1432.0888
## 3         PC  590.6732
## 4 Smartphone 1175.4427
z <- ggplot(predictedproducttype, aes(product, volume))
z + geom_col(fill = "skyblue") +
  theme(axis.text.x = element_text(angle = 50, hjust = 1))

```

Conclusion This project succesfully built and compared Three models were compared: GBM, Random Forest, and PLS model to predict sales volume and asses the influence of customer and servuces reviews

  1. Model Comparison:
  1. Three models were compared: GBM, Random Forest, and PLS.
  2. Cross-validation results showed Partial Least Squares (PLS) had consistent and balanced performance across metrics.
  3. PLS was selected as the final predictive model due to its simplicity and interpretability.
  1. Model Predictions:
  1. The PLS model successfully predicted sales volumes for new products.
  2. When aggregated, the predicted sales volumes by product type showed: Netbook and Smartphone as the highest-selling categories. Latop and PCs had relatively lower predicted sales volumes. This reflects modern consumer preferences for portable, multifunctional devices.
  1. Visualization Insights

    • The final bar chart of predicted sales clearly indicates a shift in demand toward mobile and lightweight products.
    • The “Actual vs Predicted Volume” scatter plot also showed points closely aligned with the diagonal, confirming good model accuracy.

10.1 Recommendations

  1. Focus on High-Performing Product Categories: *Increase marketing efforts for Netbook and Smartphone, as they show the highest predicted sales volumes.

2.Leverage Customer Feedback: Actively monitor and respond to service reviews and star ratings, since positive reviews strongly influence sales. Implement reward programs or automated follow-ups to encourage satisfied customers to leave reviews.

  1. Improve Low-Performing Categories:
    • For PCs and Netbooks, investigate declining sales—possibly due to market saturation or obsolescence.
    • Consider redesigning or repositioning these products to target niche markets (e.g., education, gaming, or office setups).
  2. Price Optimization:
    • Evaluate pricing strategy: while higher prices don’t necessarily deter sales, they must align with perceived product value.
    • Conduct further analysis on price elasticity to optimize margins without reducing demand.
  3. Continuous Model Updating:
    • Update the predictive model periodically as new sales data become available to maintain accuracy.
    • Integrate additional variables (e.g., seasonality, marketing spend, or competitor data) to improve prediction quality.
  4. Data-Driven Decision-Making:
    • Embed predictive analytics into business planning—particularly in inventory management, product development, and marketing strategy—to anticipate consumer needs and maximize revenue.